﻿@namespace BlazorComponent
@inherits BDomComponentBase
@typeparam TItem
@typeparam TValue

<BList @attributes="@GetAttributes(typeof(BList))">
    <BItemGroup Value="SelectedItemIndex" @ref="ItemGroup">
        @foreach (var (item, index) in Items.Select((item, index) => (item, index)))
        {
            var children = ItemChildren(item);
            <BListItem @onmousedown:preventDefault
                       Value="index"
                       OnClick="() => SelectItemAsync(item)"
                       @attributes="@GetAttributes(typeof(BListItem), data: item)">
                <BListItemContent @attributes="@GetAttributes(typeof(BListItemContent))">
                    <BListItemTitle>
                        @ItemText(item)
                    </BListItemTitle>
                </BListItemContent>
                <BListItemIcon>
                    @if (EqualityComparer<TItem>.Default.Equals(LoadingItem, item))
                    {
                        <BProgressCircular @attributes="@GetAttributes(typeof(BProgressCircular))"></BProgressCircular>
                    }
                    else if (children != null && children.Count > 0)
                    {
                        <BIcon>
                            @Icon
                        </BIcon>
                    }
                </BListItemIcon>
            </BListItem>
        }
    </BItemGroup>
</BList>

@if (HasChildren)
{
    <BCascaderColumn @key="SelectedItem"
                     TItem="TItem"
                     TValue="TValue"
                     Items="Children"
                     ColumnIndex="@(ColumnIndex + 1)"
                     SelectedItems="@SelectedItems"
                     @attributes="@GetAttributes(typeof(BCascaderColumn<,>))"
                     @ref="NextCascaderColumn">
    </BCascaderColumn>
}
